package com.oracle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oracle.mapper.GradeMapper;
import com.oracle.pojo.Grade;
import com.oracle.service.IGradeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service("gradeServiceImpl")   // 指定当前实现类的id
@Transactional
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements IGradeService {
    @Override
    public IPage<Grade> getGradeByCodition(Page<Grade> pageParam, String gradeName) {
        QueryWrapper<Grade> gradeQueryWrapper = new QueryWrapper<>();
        // 筛选条件不为空
        if (!StringUtils.isEmpty(gradeName)) {
            gradeQueryWrapper.like("name",gradeName);
        }
        // 设置排序规则，也就是在页面上按照id进行降序排列
        gradeQueryWrapper.orderByDesc("name");
        gradeQueryWrapper.orderByDesc("id");

        // 无论如何都要进行的分页条查询
        Page<Grade> page = baseMapper.selectPage(pageParam, gradeQueryWrapper);
        return page;
    }

    @Override
    public List<Grade> getGrades() {

        return baseMapper.selectList(null);
    }
}
